﻿#include<iostream>
#include<fstream>
#include<string>
using namespace std;

//1.RMB
/*class RMB
{
	int y;
	int j;
	void init(int myy, int myj)
	{
		int t = myy * 10 + myj;
		this->y = t / 10;
		this->j = t % 10;
	}
public:
	RMB(int myy=0,int myj=0)
	{
		init(myy, myj);
	}
	RMB& operator +=(const RMB& other)
	{
		int t = this->y * 10 + this->j + other.y * 10 + other.j;
		this->y = t / 10;
		this->j = t % 10;
		return *this;
	}
	void output()
	{
		cout << this->y << "元" << this->j << "角" << endl;
	}
	friend RMB operator +(RMB& r1, RMB& r2);
	friend ifstream& operator >>(ifstream& in, RMB& r);
	friend ofstream& operator <<(ofstream& out, RMB& r);
};
RMB operator +(RMB& r1, RMB& r2)
{
	int t1 = r1.y * 10 + r1.j;
	int t2 = r2.y * 10 + r2.j;
	int t = t1 + t2;
	int y = t / 10;
	int j = t % 10;
	return RMB(y,j);
}
ifstream& operator >>(ifstream& in, RMB& r)
{
	in >> r.y >> r.j;
	return in;
}
ofstream& operator <<(ofstream& out, RMB& r)
{
	out << r.y << "  " << r.j ;
	return out;
}
int main()
{
	RMB a(5, 7), b(6, 2);
	RMB c = a + b;
	cout << "c: ";
	c.output();
	a += b;
	cout << "a: ";
	a.output();
	ofstream fileout("d:\\qimo.txt");
	fileout << a;
	fileout.close();
	RMB d;
	ifstream filein("d:\\qimo.txt");
	filein >> d;
	d.output();
	filein.close();
	return 0;
}*/



//3.
/*#include<vector>
template<class Type>//声明模板
int find(Type a[], int size, Type b)
{
	int i = 0;
	for (; i < size; i++)
	{
		if (a[i] == b) return i + 1;
	}
	return -1;
}
template<class Type>
void sort(Type a[], int size)//sort排升序
{
	Type t;
	for (int i = 0; i < size-1; i++)
	{
		for (int j = 0; j < size - i-1; j++)
		{
			if (a[j] > a[j + 1])
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}
		}
	}
}
template<class Type>
int Min(Type a[], int size)
{
	Type t = a[0];
	int i;
	for (i = 1; i < size; i++)
	{
		if (a[i] < t) t = a[i];
	}
	return t;
}
template<class Type>
int Max(Type a[], int size)
{
	Type t = a[0];
	int i;
	for (i = 1; i < size; i++)
	{
		if (a[i] > t) t = a[i];
	}
	return t;
}
template<class Type>
Type Sum(Type a[], int size)
{
	Type sum = 0;
	for (int i = 0; i < size; i++)
	{
		sum += a[i];
	}
	return sum;
}
template<class Type>
Type Ave(Type a[], int size)
{
	Type sum = 0;
	for (int i = 0; i < size; i++)
	{
		sum += a[i];
	}
	return sum/size;
}
int main()
{
	int a[] = { 5,4,3,2,1 };
	cout << find(a, 5, 2) << endl;
	sort(a, 5);
	for (int i = 0; i < 5; i++) cout << a[i] << "  ";
	cout << endl;
	cout << Min(a, 5) << "  " << Max(a, 5) << endl;
	cout << Sum(a, 5) << "  " << Ave(a, 5);
	return 0;
}*/


//4.
/*class Shape
{
public:
	static const double PI;
	virtual double GetArea() = 0;
	virtual double GetPerim() = 0;
};
const double Shape::PI = 3.14;
class Circle :public Shape
{
	int r;
public:
	Circle(int myr = 0)
	{
		r = myr;
	}
	double GetArea()
	{
		return PI * r * r;
	}
	double GetPerim()
	{
		return 2 * PI * r;
	}
};
class Rectangle :public Shape
{
	int a;
	int b;
public:
	Rectangle(int mya, int myb)
	{
		a = mya;
		b = myb;
	}
	double GetArea()
	{
		return a * b;
	}
	double GetPerim()
	{
		return 2 * (a + b);
	}
};
void fun(Shape& c)
{
	cout << "面积是：" << c.GetArea() << endl;
	cout << "周长是：" << c.GetPerim() << endl;
}
int main()
{
	Circle c(2);
	fun(c);
	Rectangle t(2, 10);
	fun(t);
	return 0;
}*/

/*class Student
{
protected:
	string name;
	int grade;
public:
	Student(string myn, int myg)
	{
		name = myn;
		grade = myg;
		cout << "create a student" << endl;
	}
	bool operator >(const Student& other)
	{
		if (this->grade > other.grade)
			return true;
		else return false;
	}
	virtual ~Student()
	{
		cout << "Bye " << name << endl;
	}
	friend ostream& operator <<(ostream& out, Student& c);
};
ostream& operator <<(ostream& out,Student& c)
{
	out << "name：" << c.name << "  " << "grade：" << c.grade << endl;
	return out;
}
class GraduateStudent :public Student
{
	string teacher;
public:
	GraduateStudent(string myn, int myg,string myt):Student(myn,myg)
	{
		teacher = myt;
		cout << "create a graduatestudent" << endl;
	}
	~GraduateStudent()
	{
		cout << "Bye " << Student::name << endl;
	}
	friend ostream& operator <<(ostream& out, GraduateStudent& c);
};
ostream& operator <<(ostream& out, GraduateStudent& c)
{
	out << "name：" << c.name << "  " << "grade：" << c.grade <<"  " << "teacher：" << c.teacher << endl;
	return out;
}
int main()
{
	Student a("wang", 10);
	cout << a << endl;
	Student b("zhang", 5);
	cout << b << endl;
	cout << (a > b) << endl;
	GraduateStudent c("li", 45, "liu");
	cout << c << endl;
	GraduateStudent d("bai", 75, "zhao");
	cout << d << endl;
	cout << (c > d) << endl;
	return 0;
}*/


//5.
void copyFile(const char* sfile,const char* dfile)
{
	ifstream filein(sfile,ios::binary);//打开要读取的文件--二进制
	ofstream fileout(dfile,ios::binary);//打开要写入的文件--二进制
	char buffer[1024];//过渡区
	while (filein.eof())
	{
		filein.getline(buffer, 1024);//读取一行--getline
		int real = filein.gcount();//获取实际读取的大小
		fileout.write(buffer, real);//写入一行--write
	}
	filein.close();
	fileout.close();//一定要记得关闭
}
